$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/sysdeptreg/list?parentId=1',
        datatype: "json",
        colModel: [			
			{ label: 'deptId', name: 'deptId', index: 'dept_id', width: 50, key: true,hidden:true },
			// { label: '上级部门ID，一级部门为0', name: 'parentId', index: 'parent_id', width: 80 },
			{ label: '部门名称', name: 'name', index: 'name', width: 80 }, 			
			// { label: '排序', name: 'orderNum', index: 'order_num', width: 80 },
			// { label: '是否删除  -1：已删除  0：正常', name: 'delFlag', index: 'del_flag', width: 80 },
			{ label: '企业代码', name: 'businessCode', index: 'business_code', width: 80 }, 			
			{ label: '业企简称', name: 'businessSimple', index: 'business_simple', width: 80 }, 			
			{ label: '企业中文全称', name: 'businessAll', index: 'business_all', width: 80 },
			{ label: '企业英文全称', name: 'businessEnall', index: 'business_enall', width: 80 }, 			
			{ label: '企业联系人', name: 'businessContractpersion', index: 'business_contractpersion', width: 80 }, 			
			{ label: '业企电话', name: 'businessTel', index: 'business_tel', width: 80 }, 			
			{ label: '企业手机', name: 'businessPhone', index: 'business_phone', width: 80 }, 			
			{ label: '企业传真', name: 'businessFax', index: 'business_fax', width: 80 }, 			
			{ label: '业企网站', name: 'businessNet', index: 'business_net', width: 80 }, 			
			{ label: '业企邮箱', name: 'businessMail', index: 'business_mail', width: 80 }, 			
			{ label: '业企税号', name: 'businessTax', index: 'business_tax', width: 80 }, 			
			// { label: '业企开会行', name: 'businessAccount', index: 'business_account', width: 80 },
			// { label: '业企社会统一号码', name: 'creditCode', index: 'credit_code', width: 80 },
			// { label: '企业印章', name: 'seal', index: 'seal', width: 80 },
			// { label: '企业相关证照', name: 'picture', index: 'picture', width: 80 },
			// { label: '业企类型（1.集装箱，2散货）', name: 'businessType', index: 'business_type', width: 80 },
			// { label: '是否具备危险品运输资格', name: 'ifDanger', index: 'if_danger', width: 80 },
			// { label: '备注', name: 'remarks', index: 'remarks', width: 80 },
			// { label: '业企注册类型', name: 'businessRegistrationtype', index: 'business_Registrationtype', width: 80 },
			// { label: '企业启用日期', name: 'businessStartdate', index: 'business_startdate', width: 80 },
			// { label: '业企启用时长', name: 'businessUsedate', index: 'business_usedate', width: 80 },
			// { label: '业企缴费日期', name: 'businessMoneydate', index: 'business_moneydate', width: 80 },
			// { label: '注册企业是否开头增值服务(1微信服务，2仓储接口，3报关接口，4堆场接口，5码头接口，6其他接口)', name: 'businessValueadded', index: 'business_valueadded', width: 80 },
			{ label: '注册企业系统注册时间', name: 'businessSysrigisdate', index: 'business_sysrigisdate', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		sysDeptReg: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.sysDeptReg = {};
		},
		update: function (event) {
			var deptId = getSelectedRow();
			if(deptId == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(deptId)
		},
		saveOrUpdate: function (event) {
			var url = vm.sysDeptReg.deptId == null ? "sys/sysdeptreg/save" : "sys/sysdeptreg/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.sysDeptReg),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var deptIds = getSelectedRows();
			if(deptIds == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "sys/sysdeptreg/delete",
                    contentType: "application/json",
				    data: JSON.stringify(deptIds),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(deptId){
			$.get(baseURL + "sys/sysdeptreg/info/"+deptId, function(r){
                vm.sysDeptReg = r.sysDeptReg;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});